1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module pango.PgFont; 26 27 private import glib.Bytes; 28 private import glib.ErrorG; 29 private import glib.GException; 30 private import gobject.ObjectG; 31 private import harfbuzz.feature_t; 32 private import pango.PgContext; 33 private import pango.PgCoverage; 34 private import pango.PgFontDescription; 35 private import pango.PgFontFace; 36 private import pango.PgFontMap; 37 private import pango.PgFontMetrics; 38 private import pango.PgLanguage; 39 private import pango.c.functions; 40 public import pango.c.types; 41 42 43 /** 44 * A `PangoFont` is used to represent a font in a 45 * rendering-system-independent manner. 46 */ 47 public class PgFont : ObjectG 48 { 49 /** the main Gtk struct */ 50 protected PangoFont* pangoFont; 51 52 /** Get the main Gtk struct */ 53 public PangoFont* getPgFontStruct(bool transferOwnership = false) 54 { 55 if (transferOwnership) 56 ownedRef = false; 57 return pangoFont; 58 } 59 60 /** the main Gtk struct as a void* */ 61 protected override void* getStruct() 62 { 63 return cast(void*)pangoFont; 64 } 65 66 /** 67 * Sets our main struct and passes it to the parent class. 68 */ 69 public this (PangoFont* pangoFont, bool ownedRef = false) 70 { 71 this.pangoFont = pangoFont; 72 super(cast(GObject*)pangoFont, ownedRef); 73 } 74 75 76 /** */ 77 public static GType getType() 78 { 79 return pango_font_get_type(); 80 } 81 82 /** 83 * Frees an array of font descriptions. 84 * 85 * Params: 86 * descs = a pointer 87 * to an array of `PangoFontDescription`, may be %NULL 88 */ 89 public static void descriptionsFree(PgFontDescription[] descs) 90 { 91 PangoFontDescription*[] descsArray = new PangoFontDescription*[descs.length]; 92 for ( int i = 0; i < descs.length; i++ ) 93 { 94 descsArray[i] = descs[i].getPgFontDescriptionStruct(); 95 } 96 97 pango_font_descriptions_free(descsArray.ptr, cast(int)descs.length); 98 } 99 100 /** 101 * Loads data previously created via [method@Pango.Font.serialize]. 102 * 103 * For a discussion of the supported format, see that function. 104 * 105 * Note: to verify that the returned font is identical to 106 * the one that was serialized, you can compare @bytes to the 107 * result of serializing the font again. 108 * 109 * Params: 110 * context = a `PangoContext` 111 * bytes = the bytes containing the data 112 * 113 * Returns: a new `PangoFont` 114 * 115 * Since: 1.50 116 * 117 * Throws: GException on failure. 118 */ 119 public static PgFont deserialize(PgContext context, Bytes bytes) 120 { 121 GError* err = null; 122 123 auto __p = pango_font_deserialize((context is null) ? null : context.getPgContextStruct(), (bytes is null) ? null : bytes.getBytesStruct(), &err); 124 125 if (err !is null) 126 { 127 throw new GException( new ErrorG(err) ); 128 } 129 130 if(__p is null) 131 { 132 return null; 133 } 134 135 return ObjectG.getDObject!(PgFont)(cast(PangoFont*) __p, true); 136 } 137 138 /** 139 * Returns a description of the font, with font size set in points. 140 * 141 * Use [method@Pango.Font.describe_with_absolute_size] if you want 142 * the font size in device units. 143 * 144 * Returns: a newly-allocated `PangoFontDescription` object. 145 */ 146 public PgFontDescription describe() 147 { 148 auto __p = pango_font_describe(pangoFont); 149 150 if(__p is null) 151 { 152 return null; 153 } 154 155 return ObjectG.getDObject!(PgFontDescription)(cast(PangoFontDescription*) __p, true); 156 } 157 158 /** 159 * Returns a description of the font, with absolute font size set 160 * in device units. 161 * 162 * Use [method@Pango.Font.describe] if you want the font size in points. 163 * 164 * Returns: a newly-allocated `PangoFontDescription` object. 165 * 166 * Since: 1.14 167 */ 168 public PgFontDescription describeWithAbsoluteSize() 169 { 170 auto __p = pango_font_describe_with_absolute_size(pangoFont); 171 172 if(__p is null) 173 { 174 return null; 175 } 176 177 return ObjectG.getDObject!(PgFontDescription)(cast(PangoFontDescription*) __p, true); 178 } 179 180 /** 181 * Computes the coverage map for a given font and language tag. 182 * 183 * Params: 184 * language = the language tag 185 * 186 * Returns: a newly-allocated `PangoCoverage` 187 * object. 188 */ 189 public PgCoverage getCoverage(PgLanguage language) 190 { 191 auto __p = pango_font_get_coverage(pangoFont, (language is null) ? null : language.getPgLanguageStruct()); 192 193 if(__p is null) 194 { 195 return null; 196 } 197 198 return ObjectG.getDObject!(PgCoverage)(cast(PangoCoverage*) __p, true); 199 } 200 201 /** 202 * Gets the `PangoFontFace` to which @font belongs. 203 * 204 * Returns: the `PangoFontFace` 205 * 206 * Since: 1.46 207 */ 208 public PgFontFace getFace() 209 { 210 auto __p = pango_font_get_face(pangoFont); 211 212 if(__p is null) 213 { 214 return null; 215 } 216 217 return ObjectG.getDObject!(PgFontFace)(cast(PangoFontFace*) __p); 218 } 219 220 /** 221 * Obtain the OpenType features that are provided by the font. 222 * 223 * These are passed to the rendering system, together with features 224 * that have been explicitly set via attributes. 225 * 226 * Note that this does not include OpenType features which the 227 * rendering system enables by default. 228 * 229 * Params: 230 * features = Array to features in 231 * numFeatures = the number of used items in @features 232 * 233 * Since: 1.44 234 */ 235 public void getFeatures(out feature_t[] features, ref uint numFeatures) 236 { 237 hb_feature_t* outfeatures = null; 238 239 pango_font_get_features(pangoFont, outfeatures, cast(uint)features.length, &numFeatures); 240 241 features = new feature_t[cast(uint)features.length]; 242 for(size_t i = 0; i < cast(uint)features.length; i++) 243 { 244 features[i] = ObjectG.getDObject!(feature_t)(cast(hb_feature_t*) &outfeatures[i]); 245 } 246 } 247 248 /** 249 * Gets the font map for which the font was created. 250 * 251 * Note that the font maintains a *weak* reference to 252 * the font map, so if all references to font map are 253 * dropped, the font map will be finalized even if there 254 * are fonts created with the font map that are still alive. 255 * In that case this function will return %NULL. 256 * 257 * It is the responsibility of the user to ensure that the 258 * font map is kept alive. In most uses this is not an issue 259 * as a `PangoContext` holds a reference to the font map. 260 * 261 * Returns: the `PangoFontMap` 262 * for the font 263 * 264 * Since: 1.10 265 */ 266 public PgFontMap getFontMap() 267 { 268 auto __p = pango_font_get_font_map(pangoFont); 269 270 if(__p is null) 271 { 272 return null; 273 } 274 275 return ObjectG.getDObject!(PgFontMap)(cast(PangoFontMap*) __p); 276 } 277 278 /** 279 * Gets the logical and ink extents of a glyph within a font. 280 * 281 * The coordinate system for each rectangle has its origin at the 282 * base line and horizontal origin of the character with increasing 283 * coordinates extending to the right and down. The macros PANGO_ASCENT(), 284 * PANGO_DESCENT(), PANGO_LBEARING(), and PANGO_RBEARING() can be used to convert 285 * from the extents rectangle to more traditional font metrics. The units 286 * of the rectangles are in 1/PANGO_SCALE of a device unit. 287 * 288 * If @font is %NULL, this function gracefully sets some sane values in the 289 * output variables and returns. 290 * 291 * Params: 292 * glyph = the glyph index 293 * inkRect = rectangle used to store the extents of the glyph as drawn 294 * logicalRect = rectangle used to store the logical extents of the glyph 295 */ 296 public void getGlyphExtents(PangoGlyph glyph, out PangoRectangle inkRect, out PangoRectangle logicalRect) 297 { 298 pango_font_get_glyph_extents(pangoFont, glyph, &inkRect, &logicalRect); 299 } 300 301 /** 302 * Get a `hb_font_t` object backing this font. 303 * 304 * Note that the objects returned by this function are cached 305 * and immutable. If you need to make changes to the `hb_font_t`, 306 * use [hb_font_create_sub_font()](https://harfbuzz.github.io/harfbuzz-hb-font.html#hb-font-create-sub-font). 307 * 308 * Returns: the `hb_font_t` object 309 * backing the font 310 * 311 * Since: 1.44 312 */ 313 public hb_font_t* getHbFont() 314 { 315 return pango_font_get_hb_font(pangoFont); 316 } 317 318 /** 319 * Returns the languages that are supported by @font. 320 * 321 * If the font backend does not provide this information, 322 * %NULL is returned. For the fontconfig backend, this 323 * corresponds to the FC_LANG member of the FcPattern. 324 * 325 * The returned array is only valid as long as the font 326 * and its fontmap are valid. 327 * 328 * Returns: an array of `PangoLanguage` 329 * 330 * Since: 1.50 331 */ 332 public PgLanguage[] getLanguages() 333 { 334 auto __p = pango_font_get_languages(pangoFont); 335 336 if(__p is null) 337 { 338 return null; 339 } 340 341 PgLanguage[] arr = new PgLanguage[getArrayLength(__p)]; 342 for(int i = 0; i < getArrayLength(__p); i++) 343 { 344 arr[i] = ObjectG.getDObject!(PgLanguage)(cast(PangoLanguage*) __p[i]); 345 } 346 347 return arr; 348 } 349 350 /** 351 * Gets overall metric information for a font. 352 * 353 * Since the metrics may be substantially different for different scripts, 354 * a language tag can be provided to indicate that the metrics should be 355 * retrieved that correspond to the script(s) used by that language. 356 * 357 * If @font is %NULL, this function gracefully sets some sane values in the 358 * output variables and returns. 359 * 360 * Params: 361 * language = language tag used to determine which script 362 * to get the metrics for, or %NULL to indicate to get the metrics for 363 * the entire font. 364 * 365 * Returns: a `PangoFontMetrics` object. The caller must call 366 * [method@Pango.FontMetrics.unref] when finished using the object. 367 */ 368 public PgFontMetrics getMetrics(PgLanguage language) 369 { 370 auto __p = pango_font_get_metrics(pangoFont, (language is null) ? null : language.getPgLanguageStruct()); 371 372 if(__p is null) 373 { 374 return null; 375 } 376 377 return ObjectG.getDObject!(PgFontMetrics)(cast(PangoFontMetrics*) __p, true); 378 } 379 380 /** 381 * Returns whether the font provides a glyph for this character. 382 * 383 * Params: 384 * wc = a Unicode character 385 * 386 * Returns: `TRUE` if @font can render @wc 387 * 388 * Since: 1.44 389 */ 390 public bool hasChar(dchar wc) 391 { 392 return pango_font_has_char(pangoFont, wc) != 0; 393 } 394 395 /** 396 * Serializes the @font in a way that can be uniquely identified. 397 * 398 * There are no guarantees about the format of the output across different 399 * versions of Pango. 400 * 401 * The intended use of this function is testing, benchmarking and debugging. 402 * The format is not meant as a permanent storage format. 403 * 404 * To recreate a font from its serialized form, use [func@Pango.Font.deserialize]. 405 * 406 * Returns: a `GBytes` containing the serialized form of @font 407 * 408 * Since: 1.50 409 */ 410 public Bytes serialize() 411 { 412 auto __p = pango_font_serialize(pangoFont); 413 414 if(__p is null) 415 { 416 return null; 417 } 418 419 return new Bytes(cast(GBytes*) __p, true); 420 } 421 }